package com.example.design.ddd.pingandchong.chong.example3;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
public class Order {
    private Long id;
    private Customer customer;  
    private List<OrderItem> items = new ArrayList<>();

    /**
     * 充血模型指的是将业务逻辑尽可能地放在实体或值对象内部，而不是放在服务层
     * 计算订单总价
     * @return
     */
    public Money calculateTotal() {
        BigDecimal total = BigDecimal.ZERO;
        for (OrderItem item : items) {
            total = total.add(item.getPrice().multiply(new BigDecimal(item.getQuantity())));
        }
        return new Money(total, "USD"); // 假设货币是美元
    }

}
  